--[[
副本隐藏采集物探查逻辑
接口列表：
find		--开始探查
clearScene	--清除场景缓存的隐藏采集物探查记录
--]]
local RandomLogic = require("common.RandomLogic")
local Map = require("core.Map")
local ObjCollect = require("core.ObjCollect")
local CollectExcel = require("excel.Collect")

COPY_SCENE_HIDE = COPY_SCENE_HIDE or {}

local tempTable
local function randCollectID(t)
	tempTable = {}
	for j = 1, #t do
		tempTable[j] = {weight = t[j][2]}
	end
	local index = RandomLogic.getRandom3(tempTable)	
	return t[index][1]
end

function find(human, radius)
	local mapID = Map.scene_id_to_map_id[human.scene_id]
	
	if CollectExcel[mapID] == nil then return end
	
	COPY_SCENE_HIDE[human.scene_id] = COPY_SCENE_HIDE[human.scene_id] or {}
	
	local cf = CollectExcel[mapID]
	for i = 1, #cf do
		if COPY_SCENE_HIDE[human.scene_id][i] == nil then
			if (cf[i].x - human.x) * (cf[i].x - human.x) + (cf[i].y - human.y) * (cf[i].y - human.y) <= (radius * radius) then
				-- 在范围之内 把采集物刷出来
				local collectID = randCollectID(cf[i].collects)
				-- print("collectID:",collectID)
				local collect = ObjCollect.create(collectID)
				ObjCollect.enterScene(collect, human.scene_id, cf[i].x, cf[i].y)
				
				COPY_SCENE_HIDE[human.scene_id][i] = true		
			end
		end
	end
end

function clearScene(sceneID)
	COPY_SCENE_HIDE[sceneID] = nil
end
